define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cusaddress/index' + location.search,
                    add_url: 'cusaddress/add',
                    edit_url: 'cusaddress/edit',
                    del_url: 'cusaddress/del',
                    multi_url: 'cusaddress/multi',
                    import_url: 'cusaddress/import',
                    table: 'cusaddress',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {
                            field: 'genderstatus',
                            title: __('Genderstatus'),
                            searchList: {"1": __('Genderstatus 1'), "2": __('Genderstatus 2')},
                            formatter: Table.api.formatter.status
                        },
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'detail', title: __('Detail'), operate: 'LIKE'},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                        {
                            field: 'tagstatus',
                            title: __('Tagstatus'),
                            searchList: {"1": __('Tagstatus 1'), "2": __('Tagstatus 2'), "3": __('Tagstatus 3')},
                            formatter: Table.api.formatter.status
                        },
                        {field: 'province', title: __('Province')},
                        {field: 'city', title: __('City')},
                        {field: 'district', title: __('District')},
                        // {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'switch', title: __('Switch'), table: table, formatter: Table.api.formatter.toggle},
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'updatetime',
                            title: __('Updatetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        // {field: 'user.id', title: __('User.id')},
                        // {field: 'user.group_id', title: __('User.group_id')},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        // {field: 'user.password', title: __('User.password'), operate: 'LIKE'},
                        // {field: 'user.salt', title: __('User.salt'), operate: 'LIKE'},
                        // {field: 'user.email', title: __('User.email'), operate: 'LIKE'},
                        // {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {
                            field: 'user.avatar',
                            title: __('User.avatar'),
                            operate: 'LIKE',
                            events: Table.api.events.image,
                            formatter: Table.api.formatter.image
                        },
                        // {field: 'user.level', title: __('User.level')},
                        // {field: 'user.gender', title: __('User.gender')},
                        // {field: 'user.birthday', title: __('User.birthday'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'user.bio', title: __('User.bio'), operate: 'LIKE'},
                        // {field: 'user.money', title: __('User.money'), operate:'BETWEEN'},
                        // {field: 'user.score', title: __('User.score')},
                        // {field: 'user.successions', title: __('User.successions')},
                        // {field: 'user.maxsuccessions', title: __('User.maxsuccessions')},
                        // {field: 'user.prevtime', title: __('User.prevtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.logintime', title: __('User.logintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.loginip', title: __('User.loginip'), operate: 'LIKE'},
                        // {field: 'user.loginfailure', title: __('User.loginfailure')},
                        // {field: 'user.joinip', title: __('User.joinip'), operate: 'LIKE'},
                        // {field: 'user.jointime', title: __('User.jointime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.createtime', title: __('User.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.updatetime', title: __('User.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.token', title: __('User.token'), operate: 'LIKE'},
                        // {field: 'user.status', title: __('User.status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        // {field: 'user.verification', title: __('User.verification'), operate: 'LIKE'},
                        // {field: 'user.country', title: __('User.country'), operate: 'LIKE'},
                        // {field: 'user.province', title: __('User.province'), operate: 'LIKE'},
                        // {field: 'user.city', title: __('User.city'), operate: 'LIKE'},
                        // {field: 'user.openid', title: __('User.openid'), operate: 'LIKE'},
                        // {field: 'user.unionid', title: __('User.unionid'), operate: 'LIKE'},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});